﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace elsimulatorcsharp
{
    class Floor
    {
        // public Signal2<Integer, Integer> numberOfPeopleChanged = new Signal2<Integer, Integer>();
    // The name, door, and number of the floor.
    private static short floorCount = 0;
    private short index;
    private String name;
    private float[] doorOpen;
    
    private bool upLock;
    private bool downLock;
    
    // People
    private List<Person> people = new List<Person>();
    
    //Buttons 
    private bool upButtonPushed;
    private bool downButtonPushed;

    
    // Constructors
    public Floor(String fN) {
        upButtonPushed = false;
        downButtonPushed = false;
        upLock = false;
        downLock = false;
        index = floorCount++;
        name = fN;
        people = new List<Person>();
    }

    // Functions
    public void AddPerson(Person p) {
        people.Add(p);
        if (p.GetFloorDest() > index) {
            upButtonPushed = true;
        }
        else if (p.GetFloorDest() < index){
            downButtonPushed = true;
        }
    }
    
    public void RemovePerson(Person p) {
        people.Remove(p);
    }
    

    
    // Getter and setters
    public List<Person> GetPeople() {
        return this.people;
    }
    
    public List<Person> GetPeopleWaiting() {
        List<Person> waiting = new List<Person>();
        foreach (Person person in people){
            if (!person.IsFinished()){
                waiting.Add(person);
            }
        }
        return waiting;
    }
    
    public List<Person> GetPeopleFinished() {
        List<Person> finished = new List<Person>();
        foreach (Person person in people){
            if (person.IsFinished()){
                finished.Add(person);
            }
        }
        return finished;
    }

    void SetName(String name) {
        this.name = name;
    }

    public bool IsUpButtonOn()
    {
        return upButtonPushed;
    }
    public bool IsDownButtonOn()
    {
        return downButtonPushed;
    }

    public void SetUpButtonOn(bool pushed)
    {
        upButtonPushed = pushed;
    }

    public void SetDownButtonOn(bool pushed)
    {
        downButtonPushed = pushed;
    }
    
    public static void ResetCounter(){
        floorCount = 0;
    }

    public short GetIndex() {
        return index;
    }

    public void SetUpLock(bool l)
    {
        this.upLock = l;
    }

    public bool IsUpLockOn()
    {
        return this.upLock;
    }

    public void SetDownLock(bool l)
    {
        this.downLock = l;
    }

    public bool IsDownLockOn()
    {
        return this.downLock;
    }
    
    String GetName(){
        return this.name;
    }
}
}
